
// 定义人口数据的类型接口
// src/apis/ShanghaiTotal.ts
import request from "../utils/request";

// 定义人口数据的类型接口
export interface ShanghaiPopulationData {
    year: string;
    people: string;
}

// 获取上海总人口数据
export const getShanghaiTotalPopulation = async (): Promise<ShanghaiPopulationData[]> => {
    const response = await request.get<ShanghaiPopulationData[]>('/api/shanghai-districts-population');
    return response.data;
};

// 获取并处理上海总人口数据（转换为数字类型）
export const getShanghaiTotalPopulationProcessed = async (): Promise<{ year: number; people: number }[]> => {
    const rawData = await getShanghaiTotalPopulation();
    return rawData.map(item => ({
        year: parseInt(item.year),
        people: parseFloat(item.people)
    }));
};

//定义上海出生率死亡率相关接口
export interface ShanghaiBirthDeathRate {
    year: number;
    birthRate: number;
    deathRate: number;
}
// 获取上海出生率死亡率数据
export const getShanghaiBirthDeathRate = async (): Promise<ShanghaiBirthDeathRate[]> => {
    {
        const response = await request.get<ShanghaiBirthDeathRate[]>('/api/shanghai-districts-birth-death');
        return response.data
    }
}
//获取上海GDP数据
export interface ShanghaiGDPData {
    year: number;
    gdp: number;
}
export const getShanghaiGDP = async (): Promise<ShanghaiGDPData[]> => {
    const response = await request.get<ShanghaiGDPData[]>('/api/shanghai-districts-gdp');
    return response.data;
}
//获取上海GDP增长率数据
export interface ShanghaiGDPGrowthData {
    year: number;
    growthRate: number;
}
export const getShanghaiGDPGrowth = async (): Promise<ShanghaiGDPGrowthData[]> => {
    const response = await request.get<ShanghaiGDPGrowthData[]>('/api/shanghai-districts-gdp-growth');
    return response.data;
}